<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>收货地址</title>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">		
		<!-- 引入组件 -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@1.6/lib/vant.min.js"></script>
		<script src="html5plus://ready"></script>
		<script src="../../js/ajax.js"></script>
		<script src="../../js/area.js"></script>
		<script src="../../js/fanhui.js"></script>
	</head>
	<body>
		<div id="app">
			<header>
				<van-row style="background-color: #FF4444;padding: 10px;color: white;">
					<van-col span="10">
						<p @click="left()">
							<van-icon name="arrow-left" />
						</p>
					</van-col>
					<van-col span="10">
						<p>收货地址</p>
					</van-col>
				</van-row>
			</header>
			<section>
				<van-row>
					<van-address-edit :area-list="areaList" show-delete show-set-default
					 show-search-result :search-result="searchResult"
					 @save="onSave" @delete="onDelete"
					 @change-detail="onChangeDetail"
					 change-default="default"></van-address-edit>
				</van-row>
			</section>
			<footer>
			</footer>
		</div>
	</body>
	<script>
		var vm = new Vue({
			el: "#app",
			data: {
				areaList: address, //省市区的数据
				searchResult: [],
				user: [] ,//储存用户的所有信息
				area:{//添加的地址信息
					key:'',//用户的key值
					addressId:673,//默认地址的编号
					name:'',//用户名
					phone:'',//电话
					districtCode:'',//省市区的编号
					address:'',//详细地址
					isdefault:''//默认地址
				}
			},
			methods: {
				left() { //返回上一页
					plus.webview.close(plus.webview.currentWebview());
				},
				onSave(val) { /*点击保存按钮时触发*/
					console.log(val);
					this.area.name=val.name,
					this.area.phone=val.tel,
					this.area.key=this.user.Key,
					this.area.districtCode=val.areaCode,
					this.area.address=val.addressDetail;
					this.area.isdefault=val.isDefault;
					console.log(this.area);
					ajax({//添加收获地址
						url: "http://dsapi.ysd3g.com/API/AddShippingAddress",
						dataType: "jsonp",
						data: {
							FormData:this.area
						},
						success: function(res) {
							console.log(res);
						}
					});
				},
				onDelete() { //确认删除地址时触发
					$.toast('delete');
				},
				onChangeDetail(val) { //修改详细地址时触发--val	详情地址内容
					if (val) {
						this.searchResult = [{
							name: '安阳职业技术学院',
							address: '9号教学楼'
						},
						{
							name: '中所屯',
							address: '商颂社区'
						}
						];
					} else {
						this.searchResult = [];
					}
				},
				default: function() { //地址设为默认地址的时候

				} 
			},
			created: function() {
				this.user = plus.storage.getItem("user");
				this.user = JSON.parse(this.user);
				console.log(this.user);
				ajax({//判断这里边有没有收获地址
					url: "http://dsapi.ysd3g.com/API/MyShippingAddressList",
					dataType: "jsonp",
					data: {
						key: this.user.Key
					},
					success: function(res) {
						console.log(res);
					}
				});
			}
		});
	</script>
</html>